<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue-extend</title>
    <link rel="stylesheet" href="../../../assets/css/bootstrap.min.css">
    <script src="../../../assets/js/vue-2.5.6.js"></script>
</head>

<body>
    <div id="app">
        <component v-bind:is="who"></component>
        <button @click="changeComponent()">切换组件</button>
    </div>
</body>
<script>
    var componentA = {
        template: `<div>componentA</div>`
    }
    var componentB = {
        template: `<div>componentB</div>`
    }
    var componentC = {
        template: `<div>componentC</div>`
    }
    var app = new Vue({
        el: "#app",
        data: {
            "who": "componentA"
        },
        components: {
            "componentA": componentA,
            "componentB": componentB,
            "componentC": componentC
        },
        methods: {
            changeComponent: function() {
                if (this.who == 'componentA') {
                    this.who = 'componentB';
                } else if (this.who == 'componentB') {
                    this.who = 'componentC';
                } else {
                    this.who = 'componentA';
                }
            }
        }
    })
</script>

</html>